//type: success,warn,error,confirm,info
//title:
//content:
function createDialog(options){
	options = options||{};
	var type = options.type||'info';
	var title = options.title;
	var content = options.content || '';
	var titleColor = '#06b8ec';
	if(type === 'success'){title=title||'提示';titleColor = '#009944';}
	else if(type === 'warn'){title=title||'警告'; titleColor = '#ffba00';}
	else if(type === 'error'){title=title||'错误'; titleColor = '#e23333';}
	else if(type === 'confirm'){title=title||'确认'; titleColor = '#8e8e8e';}
	var rootPane = $('<div class="s_dRoot" style="display:none;"></div>').appendTo($("body"));
	title = title||'消息';
	var titlePane = $('<div class="s_dTitle"></div>').appendTo(rootPane);
	var titleSpan = $('<span>'+title+'</span>').appendTo(titlePane);
	var closeSpan = $('<span>x</span>').appendTo(titlePane);
	var contentPane = $('<div class="s_dContent">'+content+'</div>').appendTo(rootPane);
	var footerPane = $('<div class="s_dFooter"></div>').appendTo(rootPane);
	var okBtn = $('<button class="s_btn">确定</button>').appendTo(footerPane);
	if(type === 'confirm') var cancelBtn = $('<button class="s_btn">取消</button>').appendTo(footerPane);
	var coverPane = $('<div style="display:none;position:fixed;top:0;bottom:0;right:0;left:0;background-color:rgba(255,255,255,0.5);z-index:99998;"></div>').appendTo($('body'));
	titlePane.bindMove({content:rootPane});
	titlePane.css('background-color',titleColor);
	
	closeSpan.click(function(){
		obj.destroy();
	});
	okBtn.click(function(){
		if(typeof(options.okAction) === 'function'){
			if(options.okAction() === false){
				return;
			}
		}
		obj.destroy();
	});
	
	if(cancelBtn)
		cancelBtn.click(function(){
			if(typeof(options.cancelAction) === 'function'){
				if(options.cancelAction() === false){
					return;
				}
			}
			obj.destroy();
		});
	
	var isDestroy = false;
	var isShow = false;
	var animate;
	var obj = {
		show:function(){
			if(isDestroy) return;
			if(isShow) return;
			var o = 0;
			var f = 10;
			var z = 0.5
			rootPane.css('opacity',0);
			rootPane.css('filter','blur(10px)')
			rootPane.show();
			coverPane.show();
			isShow = true;
			if(animate){
				clearInterval(animate);
			}
			animate = setInterval(function(){
				rootPane.css('opacity',o+=0.1);
				rootPane.css('zoom',z+=0.05);
				rootPane.css('filter','blur('+(f--)+'px)');
				if(o >= 1){
					clearInterval(animate);
					rootPane.css('opacity','');
					rootPane.css('filter','');
					rootPane.css('zoom','');
                    animate = undefined;
				}
			},50);
			return this;
		},
		hide:function(e){
			if(isDestroy) return;
			if(!isShow) return;
			var o = 1;
			var f = 0;
			var z = 1;
			isShow = false;
            if(animate){
                clearInterval(animate);
            }
			animate = setInterval(function(){
				rootPane.css('opacity',o-=0.1);
				rootPane.css('zoom',z-=0.05);
				rootPane.css('filter','blur('+(f++)+'px)');
				if(o <= 0){
					clearInterval(animate);
					rootPane.hide();
					rootPane.css('opacity','');
					rootPane.css('filter','');
					rootPane.css('zoom','');
					coverPane.hide();
					if(typeof(e)==='function') e();
                    animate = undefined;
				}
			},50);
			return this;
		},
		destroy:function(){
			if(isDestroy) return;
			this.hide(function(){
				titlePane.unbindMove();
				rootPane.remove();
				coverPane.remove();
				isDestroy = true;
			});
		}
	};
	return obj;
}